package com.asset.dispoal.business.approval.service.command;

import com.asset.dispoal.business.approval.domain.db.entity.RepaymentApprover;
import com.asset.dispoal.business.approval.domain.db.mapper.RepaymentApproverMapper;
import com.asset.dispoal.business.approval.dto.RepaymentApproverResponse;
import com.asset.dispoal.business.approval.service.converter.ApprovalConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;

import java.util.Arrays;
import java.util.List;

/**
 * @description:
 * @author: yf
 * @date: 2022-10-09 10:40:23
 */
@Repository
public class GetBindApproverCommand implements BaseCommand<String, Result<RepaymentApproverResponse>> {
    @Autowired
    private RepaymentApproverMapper repaymentApproverMapper;

    @Override
    public Result<RepaymentApproverResponse> execute(String assetInstBatchId) {
        RepaymentApprover approver = repaymentApproverMapper.queryByassetInstBatchId(assetInstBatchId);
        RepaymentApproverResponse response = ApprovalConverter.INSTANCE.doToRes(approver);
        if (null != approver) {
            List<String> userIds = Arrays.asList(approver.getApproverIds().split(","));
            response.setUserIds(userIds);
        }
        return Result.ok(response);
    }
}
